function test(e, orderId) {
    var imgElements = document.querySelectorAll("#yhsc img");
    var promises = [];
    var result = "N"; // 这里使用局部变量result
    imgElements.forEach(function (item) {
        var address = "https://ctrl.189.cn";
        var imgsrc = address + item.getAttribute("src");
        var name = orderId + "_" + item.getAttribute("alt");

        let image = new Image();
        image.setAttribute("crossOrigin", "anonymous");
        image.src = imgsrc;

        let loadPromise = new Promise((resolve, reject) => {
            image.onload = function () {
                let canvas = document.createElement("canvas");
                canvas.width = image.width;
                canvas.height = image.height;
                let context = canvas.getContext("2d");
                context.drawImage(image, 0, 0, image.width, image.height);
                let url = canvas.toDataURL("image/png");

                let a = document.createElement("a");
                a.download = name || "photo";
                a.href = url;
                document.body.appendChild(a);
                a.click();
                document.body.removeChild(a);
                resolve();
            };
            image.onerror = function () {
                reject();
            };
        });

        promises.push(loadPromise);
    });

    // 使用Promise.all等待所有图片加载完成
    Promise.all(promises).then(() => {
        result = "Y"; // 这里使用局部变量result
    }).catch(() => {
        result = "N"; // 这里使用局部变量result
    });

    // 返回结果，但实际结果将在所有图片加载完成后才会更新
    return result; // 返回局部变量result的值
}
